package com.zr.gdms.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.zr.gdms.model.Function;

import com.zr.gdms.model.User;
import com.zr.gdms.service.FuncService;
import com.zr.gdms.serviceimpl.FuncServiceImpl;

import net.sf.json.JSONArray;
/**
 * 展示所有功能
 * @author 李培宁
 *
 */
public class ShowFuncsControllerLPN extends HttpServlet{

	FuncService fs = new FuncServiceImpl();
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req, resp);
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		       //设置字符编码     
				req.setCharacterEncoding("utf8");
				resp.setCharacterEncoding("utf8");
				HttpSession session = req.getSession();
				User u = (User) session.getAttribute("user");
				List<Function> funcs= fs.findFunctionByUserFid(u.getFid());
				
				//回写
				PrintWriter pw = resp.getWriter();			 
				JSONArray j = fs.getFuncs(funcs.get(0).getPid());			
				pw.write(j.toString());
				pw.flush();
				pw.close();
	}
}
